#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import shutil
import datetime

timestamp = datetime.datetime.strftime(datetime.datetime.now(), '%c')


def doTableCol(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
         <el-table-column
            prop="{0}"
            label="{1}"
            width="150"
            
            show-overflow-tooltip
          >
          </el-table-column>
    '''
    return tp.format(cname, cinfo)


def doFormCol(col):
    cname = col['cname']
    cinfo = col['cinfo']
    tp = '''
          <el-col :sm="12">
            <el-form-item prop="{0}" label="{1}">
              <el-input
                maxlength="30"
                style="width: 300px"
                v-model.trim="ruleForm.{0}"
              ></el-input>
            </el-form-item>
          </el-col>
    '''
    return tp.format(cname, cinfo)


def toVue(item):
    with open('./input/home.vue') as f:
        tp = f.read()

        tnameLow = item['tname'].lower()
        cols = item['cols']
        tableCol = ("\n").join([doTableCol(item) for item in cols])
        # print(tableCol)

        formCol = ("\n").join([doFormCol(item) for item in cols])
        # print(formCol)

        txt = tp.replace('{tableCol}', tableCol).replace(
            '{tnameLow}', tnameLow).replace('{timestamp}', timestamp).replace('{formCol}', formCol)
        # print(txt)

        print('###', tnameLow, r'./output/{0}/{0}Home.vue'.format(tnameLow))
        with open(r'./output/llbb/{0}/{0}Home.vue'.format(tnameLow), 'w') as fi:
            fi.write(txt)


def main():
    pass


if __name__ == '__main__':
    # for i in range(15):
    #     main()
    #     print(',')
    # main()
    # row = ('ACME', 50, 91.5)
    # print(*row, sep="**")

    cols = [
        {"cname": "code", "cinfo": "列代码(表内唯一)"},
        {"cname": "dataType",
            "cinfo": "数据类型枚举TEXT(\"文本型\"), INTEGER(\"整数型\"), DECIMAL(\"小数型\"), ACCOUNTANT(\"会计型\"), SHORT_DATE(\"短日期\"), DATETIME(\"长日期\");"},
        {"cname": "desensitize", "cinfo": "脱敏配置"},
        {"cname": "id", "cinfo": "主键UUID"},
        {"cname": "mandatory", "cinfo": "是否必填"},
        {"cname": "maxLength", "cinfo": "最大长度"},
        {"cname": "minLength", "cinfo": "最小长度"},
        {"cname": "name", "cinfo": "数据项名称"},
        {"cname": "pk", "cinfo": "是否主键/联合主键"},
        {"cname": "remark", "cinfo": "备注"},
        {"cname": "tableCode", "cinfo": "表格代码"},
        {"cname": "tableName", "cinfo": "表格名称"},
        {"cname": "unique", "cinfo": "是否表内唯一"}
    ]
    for item in cols:
        print('''
              {}: [
         // {{ required: true, message: "不能为空", trigger: "blur" }},
        ],'''.format(item['cname']))

    print('----success')
